package com.hsj.stream.service.impl;

import com.hsj.stream.service.MsgProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import pojo.User;

/**
 * @author:Teacher黄
 * @date:Created at 2020/01/05
 */
@Service
@SuppressWarnings("all")
@EnableBinding(Source.class) // 可以理解为是一个消息的发送管道的定义
public class MsgProducerImpl implements MsgProducer {

    @Autowired
    private MessageChannel output; // 消息的发送管道

    @Override
    public void send(User user) {
        // 发送消息
        output.send(MessageBuilder.withPayload(user).build());
    }
}
